package com.zhang.dao.impl;

import com.zhang.dao.UserDao;
import com.zhang.domain.User;
import com.zhang.util.JDBCUtils;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

public class UserDaoImpl implements UserDao {
    private JdbcTemplate jdbcTemplate = new JdbcTemplate(JDBCUtils.getDataSource());


    @Override
    public User findUsernameAndPassword(String Username, String password) {
        String sql = "SELECT * FROM `user` WHERE username = ? AND `password` = ?";
        User user = null;
        try {
            user = jdbcTemplate.queryForObject(sql,new BeanPropertyRowMapper<User>(User.class),Username,password);
        } catch (DataAccessException e) {

        }
        return user;
    }
}
